<?php
/*
  Copyright (c) 2010-02 SongCMS
  SongCMS All Rights Reserved.
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/
if(file_exists('install.php')){header('Location:install.php'); exit();}
include_once(SONGCMSROOT . 'config/config.php');
include_once(SONGCMSROOT . 'config/db.php');
include_once(SONGCMSROOT . 'inc/function.php');
include_once(SONGCMSROOT . 'tools/smarty/Smarty.class.php');
function __autoload($class_name) {
    include_once(SONGCMSROOT."class/{$class_name}.class.php");
}
if (function_exists('__autoload')) {
    spl_autoload_register('__autoload');
}
if($WebOpening==0) die(htmlspecialchars_decode($WebMaintenanceText));
$QUERY = $Query_front = preg_replace("/[\\\:\*\?\"\'<>\~\(\)\[\]\{\}\s\$]/",'',$_SERVER['QUERY_STRING']);
//多语种新闻产品处理
$QUERY = LangUrlExtract($QUERY);

if($Query_front){
    $Query_front_tmp = array();
    $Query_front = explode('/',$Query_front);
    foreach ($Query_front as $_key=>$_value){
        if( $_value=='l1' || $_value=='l2' || $_value=='l3')
        {

        }else{
            $Query_front_tmp[] = $_value;
        }
    }
    $Query_front = implode('/', $Query_front_tmp);
}
$QUERY = explode('/',$QUERY);
foreach ($QUERY as $key => $value){
	$sGET[substr($value,0,1)] = substr(trim($value),1);
}
if (!empty($sGET['w'])) $sGET['w'] = urldecode($sGET['w']);
Lang(); sFile();
if(@!include_once(SONGCMSROOT . 'config/language_'.$Lang.'.php')) die("系统没有安装第{$Lang}种语言包，该语言包应该位于 config 目录下的 language_{$Lang}.php 文件。或进入后台\"语言包管理\"添加第{$Lang}种({$WebLangName[$Lang-1]})语言包。");
$ConfigTemDir = 'templates/' . (empty($Webtemplates[($Lang-1)]) ? 'default' : $Webtemplates[($Lang-1)]) . '/';
$MyTemDir = str_replace(',','/',$sGET['d']);
$TemDir = empty($MyTemDir) ? $ConfigTemDir : $MyTemDir.'/';
$Designated = strtolower($WebDefaultHome);
if(empty($sGET['f']) && $Designated!='auto' && $Designated!='index.php' && $Designated!='./'){
	header('Location: ' . $WebDefaultHome);
	exit();
}
if($WebStaticHTML == 1 && $sGET['m'] != '1' && empty($sGET['f']) && $_COOKIE['isLogin'] != 'songcms') {
	if(is_file('home.html')){
		if($WebLangDefault == 1){
			header('Location: ./home.html');
		} else {
			header("Location: ./html/index{$WebLangDefault}.html");
		}
		exit();
	} else {
		die($Warning[25]);
	}
}
if($WebStaticHTML == 1 && $sGET['m'] == '1' && $_COOKIE['isLogin'] != 'songcms'){
	$isDynamicURL = 0;
	$WebStaticCache = 0;
	$WebForceCompil = 1;
} else {
	$isDynamicURL = 1;
}
unset($Designated,$QUERY);
$GetUrlPar = str_replace('&','',str_replace('/','',$_SERVER['QUERY_STRING']));
function Lang(){
	global $Lang,$_SERVER,$WebDefaultHome,$sGET,$WebLangKind,$WebLangDefault;
	$OSLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
	$isEnOS = (stristr($OSLang,'zh-cn') || stristr($OSLang,'zh-tw') || stristr($OSLang,'zh-hk') || stristr($OSLang,'zh-sg')) ? false : true;
	$Lang = @is_numeric($sGET['l']) ? $sGET['l'] : 0;
	if(strtolower($WebDefaultHome)=='auto' && $isEnOS===true && $Lang==0) $Lang = 2;
	if($Lang<1 || $Lang>$WebLangKind) $Lang = 1;
	unset($isEnOS,$OSLang);
	return $Lang;
}
function sFile(){
	global $File,$TemFile,$sGET,$CodeList,$TemplateSuffix;
	$File = empty($sGET['f']) ? 'home' : $sGET['f'];
	if($File=='home') $File='index';
	$TemFile = $File . $TemplateSuffix;
	$File .= '.php';
	$File = $CodeList . $File;
	if(!file_exists($File)){
		$File = $CodeList . 'index.php';
		$TemFile = "index{$TemplateSuffix}";
	}
	$TemFile = empty($sGET['e']) ? $TemFile : $sGET['e'];
	return $File;
}
function URL(){
	global $Lang,$isDynamicURL,$sGET;
	$xLang = $Lang == 1 ? NULL : "/l{$Lang}";
	$URL['LoginSub'] = "./?flogin/m1{$xLang}";
	$URL['ChanUser'] = "./?fprofile/m1{$xLang}";
	$URL['OutLogin'] = "./?flogin/aExit{$xLang}";
	$URL['GuestbookSub'] = "./?fguestbook{$xLang}";
	$URL['SurveySub'] = "./?fsurvey{$xLang}";
	$URL['RegSub'] = $sGET['f'] == 'reg' ? "./?freg{$xLang}" : "./?fprofile{$xLang}";
	if($isDynamicURL == 1){
		$URL['Reg'] = "./?freg{$xLang}";
		$URL['Home'] = $Lang == 1 ? './' : "./?l{$Lang}";
		$URL['Products'] = "./?fproducts{$xLang}";
		$URL['News'] = "./?fnews{$xLang}";
		$URL['Feedback'] = "./?ffeedback{$xLang}";
		$URL['FeedbackSub'] = "./?ffeedback{$xLang}";
		$URL['Guestbook'] = "./?fguestbook{$xLang}";
		$URL['Download'] = "./?fdownload{$xLang}";
	} else {
		$nNULL = $Lang == 1 ? '' : $Lang;
		$URL['Reg'] = "./html/other/reg{$nNULL}.html";
		$URL['Home'] = $Lang == 1 ? "./" : "./html/index{$nNULL}.html";
		$URL['Products'] = "./html/products/index{$nNULL}.html";
		$URL['News'] = "./html/news/index{$nNULL}.html";
		$URL['Feedback'] = "./html/feedback/index{$nNULL}.html";
		$URL['FeedbackSub'] = "./?m1/ffeedback{$xLang}";
		$URL['Guestbook'] = "./html/guestbook/index{$nNULL}.html";
		$URL['Download'] = "./html/download/index{$nNULL}.html";
		unset($nNULL);
	}
	return $URL;
}
function IDURL($params=array()){
	global $Lang,$isDynamicURL,$sGET;
	extract($params);
	$xLang = $Lang == 1 ? NULL : "/l{$Lang}";
	if(!is_numeric($Type)) $Type = 1;
	$rCid = explode(',',$Cid);
	$Cid = empty($rCid[$Lang-1]) ? $rCid[0] : $rCid[$Lang-1];
	switch ($Type){
		case 1 : $URL = $isDynamicURL == 1 ? "./?fpage{$xLang}/c{$Cid}" : "./html/page/{$Cid}.html"; break;
		case 2 : $URL = $isDynamicURL == 1 ? "./?fnews{$xLang}/c{$Cid}" : "./html/news/{$Cid}.html"; break;
		case 3 : $URL = $isDynamicURL == 1 ? "./?fproducts{$xLang}/c{$Cid}" : "./html/products/{$Cid}.html"; break;
		case 4 : $URL = $isDynamicURL == 1 ? "./?fdownload{$xLang}/c{$Cid}" : "./html/download/{$Cid}.html"; break;
	}
	return $URL;
}
?>